package com.hsq.androidproject.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;

import com.bumptech.glide.Glide;
import com.dl7.player.media.IjkPlayerView;

public class IjkFullscreenActivity extends AppCompatActivity {

    private static String VIDEO_URL = "http://111.161.65.92:81/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/cn-scnc3-dx.acgvideo.com/vg5/0/39/15195865-1.mp4?expires=1489767300&platform=html5&ssig=DLp_bz537CI1_05Jc_9T8g&oi=2101547035&nfa=BaDS8BUFZDb8iKo4Vfwarw==&dynamic=1";
    private static final String IMAGE_URL = "http://vimg3.ws.126.net/image/snapshot/2016/11/C/T/VC628QHCT.jpg";
    IjkPlayerView mPlayerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPlayerView = new IjkPlayerView(this);
        setContentView(mPlayerView);
        Intent intent = getIntent();
        String id=intent.getStringExtra("id");
        String path = intent.getStringExtra("path");
        String img = intent.getStringExtra("img");
        final String danmu = intent.getStringExtra("danmu");
        String title=intent.getStringExtra("title");
        Log.d("TAG", "onCreate: " + path);
        Glide.with(this).load(img).fitCenter().into(mPlayerView.mPlayerThumb);
        mPlayerView.init()
                .alwaysFullScreen()
                .enableOrientation()
                .setVideoPath(path)
                .enableDanmaku()
                .setDanmakuSource(Environment.getExternalStorageDirectory().getAbsolutePath() + "/data/" + id+".xml")
                .setTitle(title)
                .start();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPlayerView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mPlayerView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPlayerView.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (mPlayerView.handleVolumeKey(keyCode)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
        if (mPlayerView.onBackPressed()) {
            return;
        }
        super.onBackPressed();
    }

}
